var searchItem = ["exp", "goodcomment", "badcomment"];

$(document).ready(function() {
    for (var i = 0; i < searchItem.length; i++) {
        $("." + searchItem[i]).click(function() {
            $("." + $(this).attr("class")).each(function() {
                $(this).find('a').css("color", "#888888");
                $(this).find('a').css("font-size", "14px");
                $(this).attr("check", 0);
            });
            $(this).find('a').css("color", "#ff6600");
            $(this).find('a').css("font-size", "16px");
            $(this).attr("check", 1);
            doSearch();
        });
    }

    doSearch();
});

function doSearch()
{
    var whereArg = "";
    for (var i = 0; i < searchItem.length; i++) {
        $("." + searchItem[i]).each(function() {
            if ($(this).attr("check") == 1) {
                if ($(this).attr("min")) {
                    whereArg += $(this).attr("class") + ">=" + $(this).attr("min") + "#";
                }
                if ($(this).attr("max")) {
                    whereArg += $(this).attr("class") + "<=" + $(this).attr("max") + "#";
                }
            }
        })
    }
    doRequest("/HelpSite/search/search.php", whereArg.substr(0, whereArg.length - 1));
}

function doRequest(strUrl, whereArg)
{
    var ajax = InitAjax();
    ajax.open("POST", strUrl, true);
    ajax.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
    var strPost = "&wherearg=" + whereArg;
    ajax.send(strPost);

    ajax.onreadystatechange = function()
    {
        if (ajax.readyState == 4) {
            if (ajax.status == 200) {
                $("#searchRes").html(ajax.responseText);
            }
            else {
                alert(ajax.responseText);
            }
        }
    }
}

function InitAjax()
{
    var ajax=false;
    try { 
        ajax= new ActiveXObject('MSXML2.XMLHTTP.4.0');
    } catch(e) {
        try {
            ajax= new ActiveXObject('MSXML2.XMLHTTP.3.0');
        } catch(e) {
            try {
                ajax= new ActiveXObject('MSXML2.XMLHTTP.2.6');
            } catch(e) {
                try {
                    ajax= new ActiveXObject('MSXML2.XMLHTTP');
                } catch(e) {
                    try {
                        ajax= new ActiveXObject('Microsoft.XMLHTTP');
                    } catch(e) {
                        ajax = false;
                    }
                }
            }
        }
    }
    if (!ajax && typeof XMLHttpRequest!='undefined')
    {
        ajax = new XMLHttpRequest();
    }
    return ajax;
}

